<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Usersdomain extends Model
{
    protected $table = 'users_domain';
    protected $primaryKey = 'id';

    public static function getUsersDomainList($users_id)
    {
        return self::select("id","domain","created_at")->where("users_id",$users_id)->get();
    }

    public static function getLastUserDomain($users_id)
    {
        return self::select("id","domain","created_at")->where("users_id",$users_id)->orderBy("id","DESC")->get();
    }

    public static function getUsersDomainListCount($users_id)
    {
        return self::where("users_id",$users_id)->count();
    }

    public static function createUsersDomain($users_id,$domain)
    {
        return self::insert(["users_id"=>$users_id,"domain"=>$domain,"created_at"=>time()]);
    }

    public static function userDomainDelete($users_id,$id)
    {
        return self::where("id",$id)->where("users_id",$users_id)->delete();
    }
}
